package com.zsp.utils.security_jwt;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

// 密码加密工具类
@Component
public class PasswordUtil {

    @Autowired
    private PasswordEncoder encoder;

    // 密码加密
    public String encrypt(String rawPassword) {
        return encoder.encode(rawPassword);
    }

    /**
     * 密码对比
     * @param rawPassword 前密码(未加密)
     * @param hashedPassword 后密码(加密后)
     * @return
     */
    public boolean matches(String rawPassword, String hashedPassword) {
        return encoder.matches(rawPassword, hashedPassword);
    }

}

